home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACSHELL / MS1 / SHELL_SO / READEDIT.C < prev    next >
Text File  |  1992-12-02  |  7KB  |  267 lines

  1. /*
  2.  *    MacShell Source File
  3.  *
  4.  *    Copyright (c) 1989, 1990, 1991, 1992  Suick Bay Technologies.  All rights reserved.
  5.  *
  6.  *
  7.  *    RESTRICTIONS ON MacShell program and source code.
  8.  *
  9.  *    Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
  10.  *    restricted use by the owner of the CDROM "Disk to the future II".
  11.  *
  12.  *    Ñ╩No permission is granted for any commercial use without the written
  13.  *    consent of the Suick Bay Technologies.
  14.  *
  15.  *    Ñ╩No permission is granted for any redistribution of any kind use without
  16.  *    the written consent of the Suick Bay Technologies.
  17.  *
  18.  *    Ñ╩Permission is granted to use this for any personal noncommercial use.
  19.  *
  20.  *    Ñ╩You may not distribute source or executable code at all, nor may you 
  21.  *    distribute it with or within a commercial product without the written
  22.  *    consent of the Suick Bay Technologies.  Please send modifications to 
  23.  *    the author for inclusion in updates to the program.  Thanks.
  24.  *
  25.  *
  26.  *    MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  27.  *    WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  28.  *    PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  29.  *
  30.  *    SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  *    INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
  32.  *    OR ANY PART THEREOF. 
  33.  *
  34.  *    In no event will Suick Bay Technologies be liable for any lost revenue
  35.  *    or profits or other special, indirect and consequential damages, even if
  36.  *    Suick Bay Technologies has been advised of the possibility of such damages.
  37.  *
  38.  *    Suick Bay Technologies can be reached at:
  39.  *    
  40.  *    8768 Cottonwood lane
  41.  *    Maple Grove, MN 55369
  42.  *    Voice: (612) 425-7025
  43.  *    AppleLink: D5233
  44.  *    
  45.  *
  46.  *    No parts of this software may be reproduced or stored in a
  47.  *    retrieval system or transmitted in any form, or any means,
  48.  *    electronic, mechanical, photocopying, recording or otherwise,
  49.  *    without the prior written permission of Suick Bay Technologies.
  50.  *    
  51.  *    Spread the word and not the disk.
  52.  *    
  53.  *    SPK 020790    :    Added Untitled edit file on no arguments
  54.  *    SPK 012290    :    Initial
  55.  */
  56. #include    "System.h"
  57. #include     "Struct.h"
  58. #include     "EditU.h"
  59. #include    "Global.h"
  60. #include    "Mac.h"
  61. #include    "Proc.h"
  62. #include    "Path.h"
  63. #include    "Shell.h"
  64.  
  65. /*******************************************************************/
  66.  
  67. int16    read;
  68.  
  69. void    RECallBack( WHandle ShellWh, int16 ProcID, char *path, char *last,
  70.             pathType what, int16 vRefNum, long dirID )
  71. {
  72. char            str[ 256 ], name[ 256 ];
  73. OSErr            err;
  74. int16            i;
  75. long            fLen, mem;
  76. CInfoPBRec         pb;
  77. WHandle            readWh = NULL;
  78. PeditWindRec    **MyPedit;
  79. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  80.  
  81.     strcpy( str, last );
  82.     CtoPstr( str );
  83.     
  84.     if( what == pathIsFile )
  85.         {
  86.         pb.hFileInfo.ioCompletion     = NULL;
  87.         pb.hFileInfo.ioNamePtr         = (StringPtr) str;
  88.         pb.hFileInfo.ioVRefNum         = vRefNum;
  89.         pb.hFileInfo.ioDirID         = dirID;
  90.         pb.hFileInfo.ioFDirIndex     = 0;
  91.         
  92.         err = PBHGetFInfo( &pb, FALSE );
  93.         if( err )
  94.             return;
  95.     
  96.         if( pb.hFileInfo.ioFlFndrInfo.fdType == 'TEXT' )
  97.             {
  98.             fLen = pb.hFileInfo.ioFlLgLen + pb.hFileInfo.ioFlRLgLen;
  99.  
  100.             fLen += sizeof( WHandler ) + sizeof( PeditWindRec );
  101.             
  102.             /* check freemem for enough memory */
  103.             mem = FreeMem();
  104.             if( fLen <  (mem - 4096L) )
  105.                 {
  106.                 readWh = TextEditInit( TextEditWindowID, str );
  107.                 MyPedit = (PeditWindRec **) ((**readWh).thing);
  108.             
  109.                 HLock( MyPedit );
  110.                 
  111.                 sprintf( name, "%s:%s", path, last );
  112.                 
  113.                 strcpy( (char *) (**MyPedit).fileName, last );
  114.                 CtoPstr( (char *) (**MyPedit).fileName );
  115.                 
  116.                 MacToPath( name );
  117.                 procPrintf( ShellWh, ProcID, "    %s\n", name );
  118.                 
  119.                 (**MyPedit).new = 0;
  120.                 (**MyPedit).vRefNum = vRefNum;
  121.                 (**MyPedit).dirID = dirID;
  122.                 
  123.                 ReadFile( vRefNum, dirID, str, (**MyPedit).hPE );    
  124.                 
  125.                 (**MyPedit).readOnly = read;
  126.                 HUnlock( MyPedit );
  127. #ifdef    USERESINFO
  128.                 ReadResInfo( readWh );    
  129. #endif
  130.                 AdjustVScroll( readWh, FALSE );
  131.                 }
  132.             else
  133.                 procPrintf( ShellWh, ProcID,
  134.                     "insufficient memory to load file %s\n", last );
  135.             
  136.             }
  137.         }
  138. }
  139.  
  140. /*******************************************************************/
  141.  
  142. extern    int16    matches;    /* number matches to the current path */
  143.  
  144. LoadFileIntoWind( WHandle ShellWh, int16 ProcID, char *argument )
  145. {
  146. ShellWindRec    **MyShell;
  147. WHandle            editWh = NULL;
  148. OSErr            err;
  149.  
  150.     MyShell = (ShellWindRec **) (**ShellWh).thing;
  151.  
  152.     ExpandPath( ShellWh, ProcID, argument, (ProcPtr) RECallBack,
  153.             (**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
  154.  
  155.     if( matches == 0 && read == FALSE )    /* edit a new file */
  156.         {
  157.         err = CreateFile( argument, 'TEXT' );
  158.  
  159.         ExpandPath( ShellWh, ProcID, argument, (ProcPtr) RECallBack,
  160.                 (**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
  161.         }
  162.  
  163.     ResetShellPWD( ShellWh );
  164. }
  165.  
  166. /*******************************************************************/
  167.  
  168. Boolean        DoREAD( int16 ProcToken, WHandle ShellWh, int16 ProcID,
  169.                 char *string )
  170. {
  171. int16    i;
  172. char    *cp, argument[ 256 ];
  173. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  174.  
  175.     switch( ProcToken )
  176.         {
  177.         case    PROC_INIT    :
  178.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  179.             break;
  180.             
  181.         case    PROC_TERM    :
  182.         case    PROC_BREAK    :
  183.             /* Tell the shell that we're done */
  184.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  185.         
  186.             /* Turn ourself off */
  187.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  188.             break;
  189.             
  190.         case    PROC_STDIN    :
  191.             if( (**MyShell).Proc[ ProcID ].flags )
  192.                 {
  193.                 (**MyShell).Proc[ ProcID ].flags = FALSE;        
  194.                 read = TRUE;
  195.                 
  196.                 for( i = 1; i < (**MyShell).Proc[ ProcID ].argc; i++ )
  197.                     {
  198.                     GetArgv( ShellWh, ProcID, i, argument );
  199.  
  200.                     if( *argument != '-' )
  201.                         LoadFileIntoWind( ShellWh, ProcID, argument );
  202.                     }
  203.                         
  204.                 /* Tell the shell that we're done */
  205.                 SendOutToken( ShellWh, ProcID, PROC_BREAK );
  206.         
  207.                 /* Turn ourself off */
  208.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  209.                 return( FALSE );
  210.                 }
  211.         }
  212. }
  213.  
  214. /*******************************************************************/
  215.  
  216. Boolean        DoEDIT( int16 ProcToken, WHandle ShellWh, int16 ProcID,
  217.                 char *string )
  218. {
  219. int16    i, argc;
  220. char    *cp, argument[ 256 ];
  221. ShellWindRec    **MyShell;
  222.     
  223.     MyShell = (ShellWindRec **) (**ShellWh).thing;
  224.  
  225.     switch( ProcToken )
  226.         {
  227.         case    PROC_INIT    :
  228.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  229.             break;
  230.             
  231.         case    PROC_TERM    :
  232.         case    PROC_BREAK    :
  233.             /* Tell the shell that we're done */
  234.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  235.         
  236.             /* Turn ourself off */
  237.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  238.             break;
  239.             
  240.         case    PROC_STDIN    :
  241.             if( (**MyShell).Proc[ ProcID ].flags )
  242.                 {
  243.                 (**MyShell).Proc[ ProcID ].flags = FALSE;        
  244.                 read = FALSE;
  245.                 argc = (**MyShell).Proc[ ProcID ].argc;
  246.                 
  247.                 if( argc == 1 )
  248.                     TextEditInit( TextEditWindowID, "\pUntitled" );
  249.                 else
  250.                     for( i = 1; i < argc; i++ )
  251.                         {
  252.                         GetArgv( ShellWh, ProcID, i, argument );
  253.     
  254.                         if( *argument != '-' )
  255.                             LoadFileIntoWind( ShellWh, ProcID, argument );
  256.                         }
  257.                         
  258.                 /* Tell the shell that we're done */
  259.                 SendOutToken( ShellWh, ProcID, PROC_BREAK );
  260.         
  261.                 /* Turn ourself off */
  262.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  263.                 return( FALSE );
  264.                 }
  265.         }
  266. }
  267.